<%@ page language="java" pageEncoding="UTF-8" isELIgnored="false"%>
<html>
<head>
	<%
		String baseUrl = request.getContextPath();
		String roleId = request.getParameter("roleId");
	%>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script type="text/javascript">
		$(document).ready(function(){
			// 工具栏
		    var toolbar = new Ext.Toolbar({
		    	renderTo: 'editRoleToolBarDiv',
		    	items: [
				    new Ext.Button({
					    id: 'editRole-save-button',
						text: '保存',
						iconCls: 'tick'
					}),
					new Ext.Button({
					    id: 'editRole-cancel-button',
						text: '取消',
						iconCls: 'cancel'
					})
				]
			});

		 	// 编辑角色Form
			var editRoleFormPanel = new Ext.FormPanel({
				renderTo: 'editRoleFormDiv',
		        labelWidth: 60,
		        border: false,
		        bodyStyle: 'background-color:transparent;',
		        url: '${pageContext.request.contextPath}/updateRoleInfor.action',
		        items: [{
		            layout:'form',
		            border: false,
		            bodyStyle: 'padding:5px;background-color:transparent;',
		            items:[{// 角色名
			               xtype:'textfield',
			               id:'role_name',
			               name:'role_name',
			               fieldLabel:'角色名',
			               anchor:'95%',
			               allowBlank:false,
			               maxLength: 20
			           },{// 角色描述
			               xtype:'textarea',
			               id:'role_describe',
			               name:'role_describe',
			               fieldLabel:'角色描述',
			               anchor:'95%',
			               allowBlank:false,
			               maxLength: 200
			           },{// role_id
			               xtype:'hidden',
			               id:'role_id',
			               name: 'role_id'
			           },{// 操作类型
				           id:'buttonType',
			               xtype:'hidden',
			               name: 'type',
			               value: 'cancel'
			           }]
		        }]
		    });

		    // 发送请求-form初期化
			Anynote.ajaxRequest({
				baseUrl: '<%=baseUrl %>',
				baseParams: {roleId:'<%=roleId%>'},
				action: '${pageContext.request.contextPath}/getRoleID.action',
				callback: function(jsonResult){
					editRoleFormPanel.getForm().setValues(jsonResult);
				}
			});

		    // 保存按钮
		    $("#editRole-save-button").click(function(){
			    var form = editRoleFormPanel.getForm();
			    if(form.isValid()){
			    	// 发送请求
					Anynote.ajaxRequest({
						baseUrl: '<%=baseUrl %>',
						baseParams: form.getValues(),
						action: '${pageContext.request.contextPath}/updateRoleInfor.action',
						callback: function(jsonResult){
						    // location.href="${pageContext.request.contextPath}/page/index.jsp";
						    roleListGrid.getStore().reload();
							editRoleWindow.close();
						},
						showWaiting: true,
						failureMsg: '保存失败.'
					});
				}
			});
			
		 	// 取消按钮
		    $("#editRole-cancel-button").click(function(){
		    	Ext.getCmp("buttonType").setValue("cancel");
		    	editRoleWindow.close();
			});
		});
	</script>
</head>
<body>
<div id="editRoleDiv" style="width:100%;height:100%;">
	<div id="editRoleToolBarDiv"></div>
	<div id="editRoleFormDiv""></div>
</div>
</body>
</html>